package com.stockz.indicator.vsa.analyzer;

import java.util.ArrayList;
import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.core.util.BarUtil.BarValueType;
import com.stockz.indicator.movingAverage.simple.SimpleMovingAverageIndicator;
import com.stockz.indicator.stochastics.StochasticsIndicator;
import com.stockz.indicator.vsa.VsaBar;
import com.stockz.indicator.vsa.property.AverageTradeSize;
import com.stockz.indicator.vsa.property.Close;
import com.stockz.indicator.vsa.property.Region;
import com.stockz.indicator.vsa.property.Spread;
import com.stockz.indicator.vsa.property.Type;
import com.stockz.indicator.vsa.property.Volume;


public class VsaPropertyAnalyzer {
	
	private SimpleMovingAverageIndicator simpleMovingAverageIndicator;
	private StochasticsIndicator stochasticsIndicator;
	
	
	public  VsaPropertyAnalyzer(
			SimpleMovingAverageIndicator simpleMovingAverageIndicator,
			StochasticsIndicator stochasticsIndicator) {
		super();
		this.simpleMovingAverageIndicator = simpleMovingAverageIndicator;
		this.stochasticsIndicator = stochasticsIndicator;
	}

	public List<VsaBar> analyze(List<Bar> barList){
		
		simpleMovingAverageIndicator.setBarValueType(BarValueType.VOLUME);
		double vsma[] = simpleMovingAverageIndicator.getValues(barList);
		
		simpleMovingAverageIndicator.setBarValueType(BarValueType.SPREAD);
		double ssma[] = simpleMovingAverageIndicator.getValues(barList);
		
		simpleMovingAverageIndicator.setBarValueType(BarValueType.AVGTRADESIZE);
		double atssma[] = simpleMovingAverageIndicator.getValues(barList);
		
		stochasticsIndicator.setBarValueType(BarValueType.AVGPRICE);
		double pl[] = stochasticsIndicator.getValues(barList); 

		List<VsaBar> vsaBarList = new ArrayList<VsaBar>(barList.size());
		
		for(int i = 0; i < barList.size(); i++){
			VsaBar vsaBar = new VsaBar();
			AverageTradeSize.analyze(barList, atssma, i, vsaBar);
			Close.analyze(barList, i, vsaBar);
			Region.analyze(barList, pl, i, vsaBar);
			Spread.analyze(barList, ssma, i, vsaBar);
			Type.analyze(barList, i, vsaBar);
			Volume.analyze(barList, vsma, i, vsaBar);
			if(i < barList.size()-1 && i > 0){
				vsaBar.setNextType(vsaBarList.get(i-1).getType());
			}
			vsaBarList.add(vsaBar);
		}
		return vsaBarList;
	}
}
